<?php
!function_exists('adminmsg') && exit('Forbidden');


$imageTypeService = House::loadClass('houseimagetype'); /* @var $imageTypeService PW_HouseImageType */
$topTypes = $imageTypeService->getTopTypes();
$secendTypes = $imageTypeService->getSecendTypes();
$imageService = House::loadClass('houseimage'); /* @var $imageService PW_HouseImage */

if ($action == 'search') {
	InitGP(array('name','descrip','typeid','starttime','endtime','page'));
	!$page && $page =1;
	$data = array('name'=>$name,'descrip'=>$descrip,'typeid'=>$typeid,'starttime'=>$starttime,'endtime'=>$endtime);
	$images = $imageService->searchImages($data,$page);
	$totalCount = $imageService->countSearchImages($data);
	$pages = $imageService->getSearchImagesPages($data,$page,initSearchUrl($basename.'&action=search',$data));
	$ajax_basename = EncodeUrl($basename);
} elseif ($action == 'deleteimages') {
	InitGP(array('select','data'));
	InitGP(array('name','descrip','typeid','starttime','endtime'));
	$data = array('name'=>$name,'descrip'=>$descrip,'typeid'=>$typeid,'starttime'=>$starttime,'endtime'=>$endtime);
	if (!$select) {
		adminmsg('请选择要删除的图片',$_basename);
	}
	$imageService->deleteImages($select);
	adminmsg('operate_success',initSearchUrl($basename.'&action=search',$data));
} elseif ($type=='editimage') {
	define('AJAX', 1);
	InitGP(array('step','id'));
	if ($step == 2) {
		InitGP(array('typeid','descrip'));
		$imageService->updateImage($id,array('typeid'=>$typeid,'descrip'=>$descrip));
		$imageType = $imageTypeService->getType($typeid);
		echo "success|".$imageType['name']."|".$descrip;
	} else {
		$ajax_basename = EncodeUrl($basename);
		$image = $imageService->getImage($id);
		require_once PrintMode('ajax_image');
	}
	ajax_footer();
} elseif ($type=='deleteimage') {
	define('AJAX', 1);
	InitGP(array('id'));
	$imageService->deleteImage($id);
	echo 'success';
	ajax_footer();
}


function initSearchUrl($url,$data) {
	foreach ($data as $key=>$value) {
		$url .= "&$key=$value";
	}
	return $url."&";
}
require_once PrintMode('imagesearch');
?>